import pageination from '../../components/pageination/pageination.vue'
export default {
	data() {
		return {
        total:0,
        size:10,
        page:1,
        article: {}, //话题信息
        commentList: [] //话题评论列表
		}
	},
	components: {
		pageination
	},
	created() { //调用方法
		let that = this;
		//获取课程uuid
		let id = that.get("topicDetailid");
		if (id != null) {
      that.$post(
        that.urls.queryCommentById,
        {"id": id}
      )
        .then(function(res) {
          if(res.success) {
            that.article = res.data;
            that.searchTodo();
          }
        })
    }
	},
	mounted() {
		/*这块是我为了控制前端样式*/
		if($(".Announcements").height()>1000){
			$(".Child-pages").css("height","auto");
			$(".section-nav").css("height","100%");
			$(".workbench-wrapper").height($(".Announcements").height());
			$(".section-box").height($(".Announcements").height()+50);
			$(".workbench-btm").height($(".Announcements").height()-274);
		}else{
			$(".Announcements").css("height","100%");
		}

	},
	methods: { //写函数方法
		//页码切换执行方法
		pageFn: function(val, pid) {
			this.page = parseInt(val);
			//此处调分页列表数据接口
			this.searchTodo(pid);
		},
    searchTodo: function () {
      let that = this;
      if (that.article.id != null) {
        that.$post(
          //that.urls.queryArticle,
          that.urls.queryArticle,
          {
            "type": 2,
            "parentId": that.article.id,
            "pageNum": that.page,
            "pageSize": that.size
          }
        )
          .then(function(res) {
            if(res.success) {
              that.commentList = res.pageInfo.list;
              that.page = res.pageInfo.pageNum;
              that.total = res.pageInfo.total;
              /*这块是我为了控制前端样式*/
              var timer=setTimeout(function(){
         		$(".Child-pages").css("height","auto");
                $(".section-nav").css("height","100%");
                $(".workbench-wrapper").height($(".Announcements").height());
                $(".section-box").height($(".Announcements").height()+50);
                $(".workbench-btm").height($(".Announcements").height()-274);
                if($(".Announcements").height()<1000){
                	$(".Child-pages").css("height","100%");
	                $(".section-nav").css("height","96%");
	                $(".workbench-wrapper").css("height","100%");
	                $(".section-box").css("height","1080");
	                $(".workbench-btm").css("height","710");
                }
              },500)
            }
          })
        /*that.$post(
          //that.urls.queryArticle,
          that.urls.getCommentXPageInfo,
          {
            //"type": 2,
            "parentId": that.article.id,
            "pageNum": that.page,
            "pageSize": that.size
          }
        )
        .then(function(res) {
          if(res.success) {
            that.commentList = res.pageInfo.list;
            that.page = res.pageInfo.pageNum;
            that.total = res.pageInfo.total;
            var timer=setTimeout(function(){
					$(".Child-pages").css("height","auto");
					$(".section-nav").css("height","100%");
					$(".workbench-wrapper").height($(".Announcements").height());
					$(".section-box").height($(".Announcements").height()+50);
					$(".workbench-btm").height($(".Announcements").height()-274);

            },500)
          }
        })*/
      }
    },
    //递归删除评论
    deleteData: function (id) {
      let that = this;
      layer.confirm('你确定要删除吗?', {icon: 3, title:'提示'}, function(index){
        if(id != null) {
          that.$get(
            that.urls.recursionRemoveArticle + "/" + id
           )
          .then(function(res) {
            let msg = "";
            if(res.success) {
              msg = "删除成功！";
              that.searchTodo();
            } else {
              msg = "删除失败！";
            }
            layer.msg(msg, {
              time: 3000, //3s后自动关闭
            });
          })
        }
      });
    }
	}
}
